package com.quanyan.user.web;

import com.quanyan.api.APIResponse;
import com.quanyan.user.model.vo.request.ReqNewsComment;
import com.quanyan.user.model.vo.request.ReqNewsCommentDel;
import com.quanyan.user.service.NewsCommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/11/21.
 */
@RestController
@RequestMapping("/api/user/dynamic")
public class NewsCommentController {
    private static final Logger  logger = LoggerFactory.getLogger(NewsCommentController.class);

    @Autowired
    private NewsCommentService newsCommentService;

    @RequestMapping(value = "/addComment",method = RequestMethod.POST)
    public APIResponse addComment(@RequestBody ReqNewsComment reqNewsComment,HttpServletRequest request){
        try {
            Integer uid = Integer.parseInt(request.getAttribute("uid").toString());
            reqNewsComment.setUid(uid);
           return newsCommentService.addComment(reqNewsComment);
        } catch (Exception e) {
            logger.error("{}",e);
            return APIResponse.returnFail("系统异常！");
        }

    }



    @RequestMapping(value = "/delComment",method = RequestMethod.POST)
    public APIResponse delComment(@RequestBody ReqNewsCommentDel reqNewsCommentDel,HttpServletRequest request){
        try {
            Integer uid = Integer.parseInt(request.getAttribute("uid").toString());
            reqNewsCommentDel.setUid(uid);
            return newsCommentService.delComment(reqNewsCommentDel);
        } catch (Exception e) {
            logger.error("{}",e);
            return APIResponse.returnFail("系统异常！");
        }

    }



    @RequestMapping(value = "/loadComment",method = RequestMethod.POST)
    public APIResponse queryComment(@RequestBody ReqNewsComment reqNewsComment){
        try {
            return newsCommentService.queryComment(reqNewsComment);
        } catch (Exception e) {
            logger.error("{}",e);
            return APIResponse.returnFail("系统异常！");
        }
    }
}
